package com.zzptc.easyshop.dao;

import com.zzptc.easyshop.db.IDB;
import com.zzptc.easyshop.db.MysqlDB;
import com.zzptc.easyshop.factory.DaoFactoryImp;
import com.zzptc.easyshop.vo.Good;
import com.zzptc.easyshop.vo.VO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * 原子级别操作
 */
public class ProductDao implements IDAO {
    @Override
    public boolean insert(VO vo) throws SQLException {
        return false;
    }

    @Override
    public List getAll() throws SQLException {
       List list=new ArrayList();
      //获取数据库连接
        IDB db=new MysqlDB();
        Connection conn=db.getConnnection();
        //获取工具
        PreparedStatement ps=conn.prepareStatement("select * from t_easybuy_product_category");
        //没有？  不需要注入值
        //操作数据库
        ResultSet rs=ps.executeQuery();
        while (rs.next()){
            Good goog=new Good();
            goog.setEpc_id(rs.getInt(1));
            goog.setEpc_name(rs.getString(2));
            goog.setEpc_parent_id(rs.getInt(3));
            list.add(goog);

        }

        return list;
    }

    @Override
    public boolean deleteByID(VO vo) throws SQLException {
        return false;
    }

    @Override
    public boolean update(VO vo) throws SQLException {
        return false;
    }

    @Override
    public VO getByID(VO vo) throws SQLException {
        return null;
    }

    public static void main(String[] args) {
        List list=new ArrayList();
        try {
            ProductDao dao= (ProductDao) DaoFactoryImp.getInstance().createDAO("productdao");
            list=dao.getAll();
            System.out.println(list.size());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
